#include <gtest\gtest.h>
#include <Zaf\String\CString.h>



TEST(CString, StrLen) {

	ASSERT_EQ(3, Zaf::String::StrLen("abc"));
	ASSERT_EQ(3, Zaf::String::StrLen(L"abc"));
}



TEST(CString, StrCmp) {

	ASSERT_GT(0, Zaf::String::StrCmp("abc", "def"));
	ASSERT_EQ(0, Zaf::String::StrCmp("abc", "abc"));
	ASSERT_LT(0, Zaf::String::StrCmp("def", "abc"));

	ASSERT_GT(0, Zaf::String::StrCmp(L"abc", L"def"));
	ASSERT_EQ(0, Zaf::String::StrCmp(L"abc", L"abc"));
	ASSERT_LT(0, Zaf::String::StrCmp(L"def", L"abc"));
}



TEST(CString, StrICmp) {

	ASSERT_GT(0, Zaf::String::StrICmp("abc", "DEF"));
	ASSERT_EQ(0, Zaf::String::StrICmp("abc", "ABC"));
	ASSERT_LT(0, Zaf::String::StrICmp("DEF", "abc"));

	ASSERT_GT(0, Zaf::String::StrICmp(L"abc", L"DEF"));
	ASSERT_EQ(0, Zaf::String::StrICmp(L"abc", L"ABC"));
	ASSERT_LT(0, Zaf::String::StrICmp(L"DEF", L"abc"));
}



TEST(CString, StrNCmp) {

	ASSERT_GT(0, Zaf::String::StrNCmp("abc", "de", 2));
	ASSERT_EQ(0, Zaf::String::StrNCmp("abc", "ab", 2));
	ASSERT_LT(0, Zaf::String::StrNCmp("def", "ab", 2));

	ASSERT_GT(0, Zaf::String::StrNCmp(L"abc", L"de", 2));
	ASSERT_EQ(0, Zaf::String::StrNCmp(L"abc", L"ab", 2));
	ASSERT_LT(0, Zaf::String::StrNCmp(L"def", L"ab", 2));
}



TEST(CString, StrNICmp) {

	ASSERT_GT(0, Zaf::String::StrNICmp("abc", "DE", 2));
	ASSERT_EQ(0, Zaf::String::StrNICmp("abc", "AB", 2));
	ASSERT_LT(0, Zaf::String::StrNICmp("def", "AB", 2));

	ASSERT_GT(0, Zaf::String::StrNICmp(L"abc", L"DE", 2));
	ASSERT_EQ(0, Zaf::String::StrNICmp(L"abc", L"AB", 2));
	ASSERT_LT(0, Zaf::String::StrNICmp(L"def", L"AB", 2));
}



TEST(CString, StrChr) {

	//char
	const char* cstr = "abc";
	char str[] = "abc";

	ASSERT_EQ(cstr + 1, Zaf::String::StrChr(cstr, 'b'));

	char* p = Zaf::String::StrChr(str, 'b');
	ASSERT_EQ(str + 1, p);
	*p = 'd';

	ASSERT_EQ('d', str[1]);

	//wchar_t
	const wchar_t* cwstr = L"abc";
	wchar_t wstr[] = L"abc";

	ASSERT_EQ(cwstr + 1, Zaf::String::StrChr(cwstr, L'b'));

	wchar_t* wp = Zaf::String::StrChr(wstr, L'b');
	ASSERT_EQ(wstr + 1, wp);
	*wp = L'd';

	ASSERT_EQ(L'd', wstr[1]);
}



TEST(CString, StrRChr) {

	const char* cstr = "abc";
	char str[] = "abc";

	ASSERT_EQ(cstr + 1, Zaf::String::StrRChr(cstr, 'b'));

	char* p = Zaf::String::StrRChr(str, 'b');
	ASSERT_EQ(str + 1, p);
	*p = 'd';

	ASSERT_EQ('d', str[1]);

	//wchar_t
	const wchar_t* cwstr = L"abc";
	wchar_t wstr[] = L"abc";

	ASSERT_EQ(cwstr + 1, Zaf::String::StrRChr(cwstr, L'b'));

	wchar_t* wp = Zaf::String::StrRChr(wstr, L'b');
	ASSERT_EQ(wstr + 1, wp);
	*wp = L'd';

	ASSERT_EQ(L'd', wstr[1]);
}



TEST(CString, StrStr) {

	//char
	const char* cstr = "123456";
	char str[] = "123456";

	ASSERT_EQ(cstr + 2, Zaf::String::StrStr(cstr, "345"));
	
	char* p = Zaf::String::StrStr(str, "345");
	ASSERT_EQ(str + 2, p);
	*p = 'a';
	ASSERT_EQ('a', str[2]);

	//wchar_t
	const wchar_t* cwstr = L"123456";
	wchar_t wstr[] = L"123456";

	ASSERT_EQ(cwstr + 2, Zaf::String::StrStr(cwstr, L"345"));
	
	wchar_t* wp = Zaf::String::StrStr(wstr, L"345");
	ASSERT_EQ(wstr + 2, wp);
	*wp = L'a';
	ASSERT_EQ(L'a', wstr[2]);
}